import EngineUtil from "./EngineUtil";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CandleChoseCtrl extends cc.Component {
    @property(cc.Node)
    candleNode = null;
    
    @property(cc.Node)
    colorCandle = null;
    
    colorStr = "";
    colorType = null;
    showCount = 0;

    onLoad() {
        if (this.colorStr) {
            this.clickReset();
        }
    }

    onClose() {
        this.node.active = false;
    }

    showOneSelect(e) {
        let t = this.candleNode.children;
        for (let a = 0; a < t.length; a++) {
            let o = t[a],
                i = o.getChildByName("Editor_select");
            o.name == e ? (i.active = true) : (i.active = false);
        }
    }

    clickCandle(e, t) {
        if (8 != this.showCount) {
            this.colorType = parseInt(t);
            this.showOneSelect(e.currentTarget.name);
        } else {
            EngineUtil.showManageViewToast("蜡烛超过最大数量了不能点击蜡烛选择了");
        }
    }

    cliclBox() {
        if (this.colorType) {
            if (8 != this.showCount) {
                this.showCount += 1;
                this.colorStr += this.colorType.toString();
                let e = "";
                if (1 == this.colorType) {
                    e = "Hong";
                } else if (2 == this.colorType) {
                    e = "Huang";
                } else if (3 == this.colorType) {
                    e = "Lv";
                } else if (4 == this.colorType) {
                    e = "Lan";
                }
                let t = this.colorCandle.children[this.showCount - 1].getChildByName("spineNode");
                t.active = true;
                console.log("当前选择的次数=========", this.showCount);
                console.log("当前选择的皮肤=========", e);
                console.log("当前选择的颜色=========", this.colorStr);
                t.getComponent(sp.Skeleton).setSkin(e);
            } else {
                EngineUtil.showManageViewToast("蜡烛超过最大数量了请检查");
            }
        } else {
            EngineUtil.showManageViewToast("没有选择蜡烛颜色");
        }
    }

    clickSure() {
        if (8 == this.showCount) {
            console.log("当前的颜色数据", this.colorStr);
            this.node.active = false;
        } else {
            EngineUtil.showManageViewToast("蜡烛选择的数量不够请检查");
        }
    }

    clickReset() {
        this.colorStr = "";
        this.colorType = null;
        this.showCount = 0;
        this.showOneSelect("test");
        this.colorCandle.children.forEach((e) => {
            e.getChildByName("spineNode").active = false;
        });
    }

    getChoseCandleColor() {
        return this.colorStr;
    }
}
